package com.itheima.controller;

import com.itheima.domain.Account;
import com.itheima.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping(value = "/account")
public class AccountController {

    @Autowired
    //@Qualifier("accountService")
    private AccountService accountService;


    /**
     * 查询账户
     * @return
     */
    @RequestMapping(value = "/findAll")
    public String findAll()
    {
        List<Account> all = accountService.findAll();
        System.out.println(all);
        return "list";
    }

    /**
     * 保存账户
     * @param account
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/save")
    public void save(Account account, HttpServletRequest request, HttpServletResponse response) throws IOException {
        accountService.saveAccount(account);
        response.sendRedirect(request.getContextPath()+"/account/findAll");
    }
}
